<template>
	<view class="request-page">
		
		<text class="txt">Get请求状态码：{{getStatusCode}}</text>
		
		<!-- <rich-text class="txt" :nodes="getHtml"></rich-text> -->
		<button class="btn" @click="sendGet">发送Get请求</button>
		
		<text class="txt">Post请求状态码：{{postStatusCode}}</text>
		<button class="btn" @click="sendPost">发送Post请求</button>
	</view>
</template>

<script setup lang="ts">
	import { ref } from 'vue'

	const getStatusCode = ref(0)
	const postStatusCode = ref(0)
	const getHtml = ref('')
	const sendGet = ()=>{
		uni.request({
			url:'https://httpbin.org/get',
			method: 'GET',
			data: {'key': '666'},
			sslVerify: false,
			success:(res)=>{
				getStatusCode.value = res.statusCode
				//getHtml.value = res.data as string
				console.log('1111111111res',res)
			},
			fail: (err)=>{
				console.log('1111111111err',err)
			}
		})
	}
	
	const sendPost = ()=>{
		uni.request({
			url:'https://httpbin.org/post',
			method: 'POST',
			data: {'key': '666'},
			sslVerify: false,
			success:(res)=>{
				postStatusCode.value = res.statusCode
				//getHtml.value = res.data as string
				console.log('1111111111res',res)
			},
			fail: (err)=>{
				console.log('1111111111err',err)
			}
		})
	}

</script>

<style lang="less" scoped>
	.request-page{
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		width: 100%;
		height: 100%;
		padding: 20px;
		align-items: center;
		justify-content: center;
		
		.txt,.btn {
			margin-top: 25px;
		}
	}
</style>
